﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ComLib.ComType
{
    public struct IntRangle
    {
        public IntRangle(int min, int max)
        {
            if (min > max)
            {
                Max = min;
                Min = max;  
            }
            else
            {
                Max = max;
                Min = min;       
            }           
        }

        public int Max;

        public int Min;

        public override string ToString()
        {
            return string.Format("({0}, {1})", Min, Max);
        }

        public bool InRangle(int v)
        {
            if (v >= Min && v <= Max)
            {
                return true;
            }
            return false;
        }
    };

    public struct RangleUInt
    {
        public RangleUInt(uint min, uint max)
        {
            Max = max;
            Min = min;
            Medius = (max + min) / 2;
        }

        public uint Max;
        public uint Min;
        public uint Medius;
    };

    public struct RangleDouble
    {
        public RangleDouble(double min, double max)
        {
            Max = max;
            Min = min;
        }

        public double Max;
        public double Min;
    };

    public struct RangleFloat
    {
        public RangleFloat(float min, float max)
        {
            Min = min;
            Max = max;
            Medius = (max + min) / 2;
        }

        public RangleFloat(uint min, uint max, uint whole)
        {
            if(whole != 0 && min <= max && whole >= max)
            {
                Max = max / (float)whole;
                Min = min / (float)whole;
                Medius = (Max + Min) / 2;
            }     
            else
            {
                Max = 0.0f;
                Min = 0.0f;
                Medius = 0.0f;
            }
        }

        public float Max;
        public float Min;
        public float Medius;
    }
}
